package com.example.yuejian.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.ActivityUtils;
import com.bumptech.glide.Glide;
import com.example.yuejian.R;
import com.example.yuejian.activity.ClubEntityDetail;
import com.example.yuejian.activity.MasterActivityDetail;
import com.example.yuejian.activity.TrainDetailActivity;
import com.example.yuejian.activity.VideoActivity;
import com.example.yuejian.bean.SearchEntity;
import com.example.yuejian.bean.VideoEntity;
import com.yuyh.easyadapter.AdapterImageLoader;
import com.yuyh.easyadapter.recyclerview.EasyRVAdapter;
import com.yuyh.easyadapter.recyclerview.EasyRVHolder;

import java.util.List;

public class SearchAdapter extends EasyRVAdapter<SearchEntity> {

    public SearchAdapter(Context context, List<SearchEntity> list, int... layoutIds) {
        super(context, list, layoutIds);
    }

    @Override
    protected void onBindData(EasyRVHolder viewHolder, final int position, final SearchEntity item) {

        switch (item.getFlag()){
            case 1:
                viewHolder.setText(R.id.name, item.getClub_name());
                viewHolder.getItemView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(v.getContext(),ClubEntityDetail.class);
                        intent.putExtra("cid",item.getClub_id());
                        ActivityUtils.startActivity(intent);
                    }
                });
                break;
            case 2:
                viewHolder.setText(R.id.name, item.getTrain_name());
                viewHolder.getItemView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(v.getContext(),TrainDetailActivity.class);
                        intent.putExtra("tid",item.getTrain_id());
                        ActivityUtils.startActivity(intent);
                    }
                });

                break;
            case 3:
                viewHolder.setText(R.id.name, item.getMaster_name());
                viewHolder.getItemView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent =new Intent(v.getContext(),MasterActivityDetail.class);
                        intent.putExtra("mid",item.getMaster_id());
                        ActivityUtils.startActivity(intent);

                    }
                });
                break;
        }
    }

    @Override
    public int getLayoutIndex(int position, SearchEntity item) {
        return 0;
    }
    @Override
    public AdapterImageLoader.ImageLoader getImageLoader() {
        // 重写该方法，以替换全局初始化的ImageLoader
        return new AdapterImageLoader.ImageLoader() {
            @Override
            public void loadImage(Context context, String url, ImageView view) {
                Glide.with(context)
                        .load(url)
                        .into(view);
            }
        };
    }
}